﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WH0225
{
    public partial class Form1 : Form
    {
        //定义数组
        public static int[] arr = { 2, 389, 98, 37, 877, 31, 9 };
        public Form1()
        {
            this.InitializeComponent();
            this.Init();
        }

        public void Init()
        {
            //初始化界面设置
            this.AutoSizeMode = AutoSizeMode.GrowAndShrink;
            this.AutoSize = false;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            //设置文本框不能由用户修改
            this.SetNumReadOnly(true);
        }

        private void SetNumReadOnly(bool isReadOnly)
        {
            this.tb_max.ReadOnly = isReadOnly;
            this.tb_min.ReadOnly = isReadOnly;
            this.tb_ave.ReadOnly = isReadOnly;
        }
        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.tb_max.Text = getMax(arr).ToString();
            this.tb_min.Text = getMin(arr).ToString();
            this.tb_ave.Text = getAve(arr).ToString();
        }

        public int getMax(int[] array)
        {
            int max = array[0];
            for(int i = 0; i < array.Length; i++)
            {
                if(max < array[i])
                {
                    max = array[i];
                }
            }return max;
        }

        public int getMin(int[] array)
        {
            int min = array[0];
            for (int i = 0; i < array.Length; i++)
            {
                if (min > array[i])
                {
                    min = array[i];
                }
            }
            return min;
        }

        public int getAve(int[] array)
        {
            int all = 0;
            for(int i = 0; i < array.Length; i++)
            {
                all += array[i];
            }
            int ave = all / array.Length;
            return ave;
        }
    }
}
